package com.example.lib_base.manager

import android.util.Log
import com.example.lib_base.model.Song

class SongManager private constructor(){
    var songs = listOf<Song>()
    private val bmobManager = BmobManager.getInstance()

    companion object{
        private var instance:SongManager? = null

        fun getInstance():SongManager?{
            if(instance == null){
                synchronized(this){
                    if(instance == null){
                        instance = SongManager()
                    }
                }
            }
            return instance!!
        }
    }

    //获取数据
    fun requireData(callback:(Boolean,List<Song>)->Unit){
        bmobManager.querySong {
            if(it == null){
                callback(false,songs)
                return@querySong
            }

            if(it.isEmpty()){
                callback(false,songs)
                return@querySong
            }else{
                songs = it
                callback(true,songs)

            }

        }
    }

}